登录 白背景

1465. 切割后面积最大的蛋糕

https://leetcode.cn/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts/description

  • 难度:undefined
  • 提交时间:2023.10.27 15:56
  • 60ms 击败 100.00%使用 Go 的用户
  • 8.34MB 击败 33.33%使用 Go 的用户

func maxArea(h int, w int, horizontalCuts []int, verticalCuts []int) int {
    horizontalCuts = append(horizontalCuts, h)
    verticalCuts = append(verticalCuts, w)
    sort.Ints(horizontalCuts)
    sort.Ints(verticalCuts)
    maxH := 1
    lastH := 0
    for _, h = range horizontalCuts {
        if h-lastH > maxH {
            maxH = h - lastH
        }
        lastH = h
    }
    maxW := 1
    lastW := 0
    for _, w = range verticalCuts {
        if w-lastW > maxW {
            maxW = w - lastW
        }
        lastW = w
    }
    //fmt.Println(maxH, maxW, maxH*maxW)
    return (maxH * maxW) % 1000000007
}